package com.listeningframework.boot.autoconfigure.orm.jpa.support;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.listeningframework.boot.commons.utils.DateFormatUtils;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.Date;

/**
 * Listening Jpa Entity
 * 
 * @author listening
 * @version $Id: ListeningJpaEntity.java, v 0.1 2015年5月1日 下午5:44:31 listening Exp $
 */
@MappedSuperclass
public abstract class ListeningJpaEntity extends ListeningJpaEntityKey implements Serializable {
    /**  */
    private static final long serialVersionUID = 3487641970658816538L;

    /**
     * 创建人
     */
    @Column(name = "created_by", nullable = false, updatable = false, length = 50)
    protected String          createdBy;
    /**
     * 创建日期
     */
    @JsonIgnore
    @Column(name = "created_date", nullable = false, updatable = false)
    protected Date            createdDate      = new Date();
    /**
     * 更新人
     */
    @Column(name = "updated_by", nullable = false, length = 50)
    protected String          updatedBy;
    /**
     * 更新日期
     */
    @JsonIgnore
    @Column(name = "updated_date", nullable = false)
    protected Date            updatedDate      = new Date();

    protected ListeningJpaEntity() {
        setCreateInfo("listening");
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(String updatedBy) {
        this.updatedBy = updatedBy;
    }

    public Date getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Date updatedDate) {
        this.updatedDate = updatedDate;
    }

    public void setCreateInfo(String userInfo) {
        this.setCreatedBy(userInfo);
        this.setUpdatedBy(userInfo);
        Date now = new Date();
        this.setCreatedDate(now);
        this.setUpdatedDate(now);
    }

    public String getUpdatedDateString() {
        return DateFormatUtils.datetime2string(updatedDate);
    }

    public String getCreatedDateString() {
        return DateFormatUtils.datetime2string(createdDate);
    }
}
